layui.use(top.layuiuse,
    function () {
        var form = layui.form;
        var watermark = layui.watermark;
        var tabs = layui.tabs;
        var kaPublic = layui.kaPublic;
        var kahtml = layui.kahtml;
        var $ = layui.jquery;
        var kaAjax = layui.kaAjax;
        var kaBgUrl = layui.kaBgUrl;
        var kaLog = layui.kaLog;
        var kaLanguage = layui.kaLanguage;
        var kaForm = layui.kaForm;
        var kaInterval = layui.kaInterval;
        var layuiFormId = "retrievePassword-form-val-filter";
        var kaStepTabs = layui.kaStepTabs;
        // 公共
        var bodyUrl = kaPublic.initBodySetUp();
        // 返回登录
        kaPublic.setUploginHtml("retrievePasswordLoginSetUp", 1);
        // 加载水印
        loadingWatermark(watermark)
        // 获取语言类型
        kaLanguage.renderingOption("languageSelect");
        // 初始化步骤
        kaStepTabs.init({
            id: "retrievePassword",
            headers: [{
                title: "填写帐号"
            }, {
                title: "身份验证"
            }, {
                title: "设置新密码"
            }, {
                title: "完成"
            }],
            bodys: [{
                code: "fillInAccount",
                callBack: function () { // 提交
                    top.fillInAccountMsgId = "";
                    top.identityVerifyMsgId = "";
                    top.setNewPassWordMsgId = "";
                    // 初始化租户
                    layui.kaAjax.ajax(layui.kaBgUrl.url("getTenant"), function (rs) { // rs 返回的驗證碼 JSON
                        if (rs.code == 200) {
                            if (rs.data.length > 0) {
                                layui.form.val(layuiFormId, { "tenantId": rs.data[0].id, "tenantName": rs.data[0].name });
                            } else {
                                layui.kaMsg.error(rs.msg, "无效的租户编码");
                                return false;
                            }
                        } else {
                            layui.kaMsg.error(rs.msg, JSON.stringify(rs));
                        }
                    }, { code: bodyUrl.code });
                    //获取驗證碼按钮
                    $("#verificationImgkbq").unbind(); //先取消綁定事件
                    $("#verificationImgkbq").click(function () {
                        kaAjax.ajax(kaBgUrl.url("verificationImage"), function (rs) {
                            if (rs.code == 200) {
                                var imgsrc = "data:image/gif;base64," + rs.img;//驗證碼
                                $("#verificationImg").attr("src", imgsrc);
                            }
                        })
                    });
                    // 验证码看不清
                    $("#verificationImgkbq").click();
                    kaForm.submit("retrievePassword", "retrievePasswordFillInAccount", "retrievePasswordFillInAccount");
                }
            }, {
                code: "identityVerify",
                callBack: function () {
                    if (top.fillInAccountMsgId == undefined || top.fillInAccountMsgId == null || top.fillInAccountMsgId == "") { //跳转第一
                        layui.tabs.change("retrievePassword", 0);
                        return false;
                    }
                    top.identityVerifyMsgId = "";
                    top.setNewPassWordMsgId = "";
                    layui.kaAjax.ajax(layui.kaBgUrl.url("getFillInAccount"), function (rs) { // rs 返回的驗證碼 JSON
                        if (rs.code == 200) {
                            layui.form.val(layuiFormId, { "tenantId": rs.data.tenantId, "tenantName": rs.data.tenantName, "username": rs.data.username, "anonymousphone": rs.data.anonymousphone });
                        } else {
                            layui.kaMsg.error(rs.msg, JSON.stringify(rs));
                        }
                    }, { id: top.fillInAccountMsgId });
                    layui.kaPhonenVerCode.init("PhonenVerCodeButton", "phone", "retrievePassword-form-val-filter", 1);
                    kaForm.submit("retrievePassword", "retrievePasswordIdentityVerify", "retrievePasswordIdentityVerify");
                }
            }, {
                code: "setNewPassWord",
                callBack: function () {
                    if (top.identityVerifyMsgId == undefined || top.identityVerifyMsgId == null || top.identityVerifyMsgId == "") { //跳转第一
                        layui.tabs.change("retrievePassword", 0);
                        return false;
                    }
                    top.setNewPassWordMsgId = "";
                    layui.kaAjax.ajax(layui.kaBgUrl.url("getIdentityVerify"), function (rs) { // rs 返回的驗證碼 JSON
                        if (rs.code == 200) {
                            if (rs.data.judge) {
                                layui.form.val(layuiFormId, { "setNewPassWordMsgId": rs.data.id });
                            } else {

                            }
                        } else {
                            layui.kaMsg.error(rs.msg, JSON.stringify(rs));
                        }
                    }, { id: top.identityVerifyMsgId });
                    kaForm.submit("retrievePassword", "retrievePasswordSetNewPassWord", "retrievePasswordSetNewPassWord");
                }
            }, {
                code: "complete",
                callBack: function () {
                    kaPublic.setUploginHtml("stepTabsRetrievePasswordCompleteBtton", 2);
                }
            }]
        });

    }
)